#include <my/Logger/Logger.h>
#include <my/Config.h>
#include <fstream>
#include <iostream>

namespace my {

    bool Logger::_initialized = false;

    Logger::Logger()
    {

    }

    Logger::~Logger()
    {

    }

    void Logger::init()
    {
        std::ofstream file("log.txt", std::ios::trunc);
        _initialized = true;
    }

    void Logger::write(const char* msg)
    {
        std::string data(msg);
        Logger::write(data);
    }

    void Logger::write(const std::string& msg)
    {
        if(!Logger::_initialized)   Logger::init();

        std::ofstream file("log.txt", std::ios::app);

        if(file)
        {
            file << msg << std::endl;
            file.close();
        }
        else
            std::cerr << "Error at the opening of file : log.txt" << std::endl;

        if(DEBUG)
            std::cout << msg << std::endl;
    }


}
